using System.Text.Json;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using Newtonsoft.Json.Linq;
using Seer.SeerSocket;



[ApiController]
[Route("[controller]/[action]")]
public class UserController : ControllerBase
{
    private readonly ILogger<UserController> logger;
    private readonly SqliteDbContext dbContext;
    // private readonly IDistributedCacheHelper helper;
    private readonly SeerSocket seerSocket;

    // public UserController(ILogger<UserController> logger, SqliteDbContext dbContext, IDistributedCacheHelper helper, SeerSocket seerSocket)
    public UserController(ILogger<UserController> logger, SqliteDbContext dbContext,  SeerSocket seerSocket)
    {
        this.logger = logger;
        this.dbContext = dbContext;
        // this.helper = helper;
        this.seerSocket = seerSocket;
    }

    [HttpGet]
    public async Task<string> Get()
    {
        // 读取 JSON 文件
        string json = System.IO.File.ReadAllText(@"F:\song\SeerAGV\RCS\Db\all1.json");
        // 序列化 JSON
        string serializedJson = JsonSerializer.Serialize(json);

        // return await helper.GetOrCreateAsync<string>("all1", async e => this.seerSocket.Send(0x044c), 3);
        return serializedJson; 
    }

    [HttpPost]
    public async Task Save(UserRequest user)
    {
        dbContext.Users.Add(new User { NickName = user.NickName });
        await dbContext.SaveChangesAsync();
    }
}





